package basicutil.common;

public final class StringUtil {
    public static boolean isEmpty(String s) {
        return s == null || s.trim().isEmpty();
    }

    public static boolean isNotEmpty(String s) {
        return !isEmpty(s);
    }

    public static String getOrDefault(String s, String defaultStr) {
        return isEmpty(s) ? defaultStr : s;
    }

    public static Integer toInt(String s) {
        try {
            return Integer.parseInt(s.trim());
        } catch (Exception ignored) {
            return null;
        }
    }

    public static int toIntDefault0(String s) {
        try {
            return Integer.parseInt(s.trim());
        } catch (Exception ignored) {
            return 0;
        }
    }
}
